<template>
  <div>
    <el-button type="info" size="mini" style="margin-bottom: 10px"><a href="/#/main/waybill__onlineInquiryFourceRelateRamark__list" target="_blank">强制关联日志</a></el-button>
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <span>强制修改关联  <span style="font-weight: bold;color: #FF7575;">使用该功能前，请一定联系对应渠道</span></span>
      </div>
      <el-form ref="forceRelateOnlineInquriyWaybillForm" :inline="true" :model="forceRelateOnlineInquriyWaybill"
               :rules="rules" size="mini">
        <el-form-item label="询单号" prop="onlineInquiryNoAndIndex">
          <el-input v-model="forceRelateOnlineInquriyWaybill.onlineInquiryNoAndIndex" placeholder="询单号-方案序号"></el-input>
        </el-form-item>
        <el-form-item label="运单号" prop="waybillNos">
          <el-input v-model="forceRelateOnlineInquriyWaybill.waybillNos" placeholder="多个运单请用,隔开"></el-input>
        </el-form-item>
        <el-form-item label="对外卖价" prop="currency">
          <el-select v-model="forceRelateOnlineInquriyWaybill.currency">
            <el-option v-for="(k, v) in currencyMap" :key="k" :label="currencyMap[v]" :value="v"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item prop="inquiryPrice">
          <el-input v-model="forceRelateOnlineInquriyWaybill.inquiryPrice"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submitForceRelateForm" v-loading.fullscreen.lock="fullscreenLoading">修改关联</el-button>
        </el-form-item>
      </el-form>
    </el-card>
    <el-card class="box-card" style="margin-top:20px;">
      <div slot="header" class="clearfix">
        <span>强制取消  <span
          style="font-weight: bold;color: #FF7575;">使用该功能前，请一定联系对应渠道，清空运单询单关联，将运单重置为公布价，将询单所有关联关系取消</span></span>
      </div>
      <el-form ref="forceCancleForm" :model="forceCancleOnlineInquriyWaybill" :inline="true" :rules="rulesCalcle"
               size="mini">
        <el-form-item label="询单号" prop="onlineInquiryNo">
          <el-input v-model="forceCancleOnlineInquriyWaybill.onlineInquiryNo"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submitForceCancleForm" v-loading.fullscreen.lock="fullscreenLoading">取消询单</el-button>
        </el-form-item>
      </el-form>
    </el-card>
    <el-card class="box-card" style="margin-top:20px;">
      <div slot="header" class="clearfix">
        <span>删除询价单  <span style="font-weight: bold;color: #FF7575;">如果询单已关联运单的询价单，请先取消关联</span></span>
      </div>
      <el-form ref="forceDeleteForm" :model="forceDeleteOnlineInquriy" :inline="true" :rules="rulesDelete" size="mini">
        <el-form-item label="询单号" prop="onlineInquiryNo">
          <el-input v-model="forceDeleteOnlineInquriy.onlineInquiryNo"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submitForceDeleteForm" v-loading.fullscreen.lock="fullscreenLoading">删除询价单</el-button>
        </el-form-item>
      </el-form>
    </el-card>


  </div>


</template>
<script>
  import {ajax} from "@/store/yg/common/utils";
  import axios from "axios";
  import * as constant from "@/store/yg/common/constant";
  import {m} from "@/store/yg/common/local";

  export default {
    components: {},
    props: [],
    data() {
      return {
        fullscreenLoading: false,
        forceRelateOnlineInquriyWaybill: {
          onlineInquiryNoAndIndex: '',
          waybillNos: '',
          currency: 'RMB',
          inquiryPrice: ''
        },
        forceCancleOnlineInquriyWaybill: {
          onlineInquiryNo: ''
        },
        forceDeleteOnlineInquriy: {
          onlineInquiryNo: ''
        },
        rules: {
          onlineInquiryNoAndIndex: [{
            required: true,
            message: '请输入询单号',
            trigger: 'blur'
          }],
          waybillNos: [{
            required: true,
            message: '请输入运单号',
            trigger: 'blur'
          }],
          inquiryPrice: [{
            required: true,
            message: '请输入对外卖价',
            trigger: 'blur'
          }],
        },
        rulesCalcle: {
          onlineInquiryNo: [{
            required: true,
            message: '请输入询单号',
            trigger: 'blur'
          }]
        },
        rulesDelete: {
          onlineInquiryNo: [{
            required: true,
            message: '请输入询单号',
            trigger: 'blur'
          }]
        },
        currencyMap: {},
      };
    },
    computed: {},
    watch: {},
    created() {
    },
    mounted() {
      this.initOptions();
    },
    methods: {
      initOptions() {
        const sourcesName = "currencyCodeSource";
        let uri = "/api/entry/source?bean=" + sourcesName;
        axios.post(constant.API_SERVER + uri).then(response => {
          this.currencyMap = response.data;
        }, error => {
          console.info(error);
        })
      },
      submitForceRelateForm() {
        this.$refs['forceRelateOnlineInquriyWaybillForm'].validate(valid => {
          if (!valid) return
          this.forceRelateOnlineInquriyWaybillFunction(this.forceRelateOnlineInquriyWaybill);
        })
      },
      submitForceCancleForm() {
        this.$refs['forceCancleForm'].validate(valid => {
          if (!valid) return
          this.forceCancleFunction(this.forceCancleOnlineInquriyWaybill);
        })
      },
      submitForceDeleteForm() {
        this.$refs['forceDeleteForm'].validate(valid => {
          if (!valid) return
          this.forceDeleteFunction(this.forceDeleteOnlineInquriy);
        })
      },
      async forceRelateOnlineInquriyWaybillFunction(params) {
        this.fullscreenLoading = true;
        const res = await ajax("forceRelateOnlineInquriyWaybill", params);
        this.fullscreenLoading = false;
        if (res.code == 200) {
          this.$message.success("操作成功");
        } else if (res.code == 300) {
          this.$confirm(m(res.message), '警告', {
            confirmButtonText: '强制关联',
            cancelButtonText: '取消关联',
            type: 'warning',
            dangerouslyUseHTMLString: true,
          }).then(_ => {
            params["isAgainConfirm"] = 1;
            this.forceRelateOnlineInquriyWaybillFunction(params);
          }).catch(_ => {
          });
        } else {
          this.$message.error(m(res.message));
        }
      },
      async forceCancleFunction(params) {
        this.fullscreenLoading = true;
        const res = await ajax("forceCancleOnlineInquriyWaybill", params);
        this.fullscreenLoading = false;
        if (res.code != 200) {
          this.$message.error(m(res.message));
        } else {
          this.$message.success("操作成功")
        }
      },
      async forceDeleteFunction(params) {
        this.fullscreenLoading = true;
        const res = await ajax("forceDeleteOnlineInquriy", params);
        this.fullscreenLoading = false;
        if (res.code != 200) {
          this.$message.error(m(res.message));
        } else {
          this.$message.success("操作成功")
        }
      }
    }
  };

</script>
